/**
 * 
 */
package common;

/**
 * @author vladimir
 * 
 */
public class Range {
	/*
	 * Produce an int sequence [0..n)
	 */
	public static int[] range(int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = i;
		}
		return result;
	}

	/*
	 * Produce an int sequence [start..end)
	 */
	public static int[] range(int start, int end) {
		int sz = end - start;
		int[] result = new int[sz];
		for (int i = 0; i < sz; i++) {
			result[i] = start + i;
		}
		return result;
	}

	/*
	 * Produce an int sequence [start..end) incremented by step
	 */
	public static int[] range(int start, int end, int step) {
		int sz = (int) ((end - start) / step);

		if ((end - start) % step != 0)
			sz += 1;
		int[] result = new int[sz];
		for (int i = 0; i < sz; i++)
			result[i] = start + (i * step);
		return result;
	}

	/*
	 * public static double[] range(double n) { double[] result = new
	 * double[(int) n]; for (int i = 0; i < n; i++) { result[i] = i; } return
	 * result; }
	 */
	/*
	 * Produce a double sequence [start..end)
	 */
	/*
	 * public static double[] range(double start, double end) { int sz = (int)
	 * (end - start); double[] result = new double[sz]; for (int i = 0; i < sz;
	 * i++) { result[i] = start + i; } return result; }
	 */
	/*
	 * Produce an double sequence [start..end) incremented by step
	 */

	public static double[] range(double start, double end, double step) {
		if (start == end) {
			double[] result = new double[1];
			result[0] = start;
			return result;
		} else {
			int sz = (int) ((end - start) / step);
			double[] result = new double[sz];
			for (int i = 0; i < sz; i++)
				result[i] = start + (i * step);
			return result;
		}
	}

}
